<!DOCTYPE html>


<html lang="zn-CH">


<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="git相关操作问题" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    java相关工具类（excel导出） |  小熊的博客
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="http://www.cdn.adingxiong.com/b5363a06dc744d79a94021492bcefe27" />
  
  
<link rel="stylesheet" href="/blog/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/blog/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

<link rel="alternate" href="/blog/atom.xml" title="小熊的博客" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content on">
      <section class="outer">
  <article id="post-导出Excel文档（定宽自动换行）" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  java相关工具类（excel导出）
</h1>
 

    </header>
    

    
    <div class="article-meta">
      <a href="/blog/2020/04/18/%E5%AF%BC%E5%87%BAExcel%E6%96%87%E6%A1%A3%EF%BC%88%E5%AE%9A%E5%AE%BD%E8%87%AA%E5%8A%A8%E6%8D%A2%E8%A1%8C%EF%BC%89/" class="article-date">
  <time datetime="2020-04-18T05:47:36.286Z" itemprop="datePublished">2020-04-18</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/blog/categories/%E5%B7%A5%E5%85%B7%E7%B1%BB/">工具类</a>
  </div>

      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">2.7k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">14 min</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    
    <div class="article-entry" itemprop="articleBody">
      
      

      
      <h4 id="工具类"><a href="#工具类" class="headerlink" title="工具类"></a>工具类</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br><span class="line">534</span><br><span class="line">535</span><br><span class="line">536</span><br><span class="line">537</span><br><span class="line">538</span><br><span class="line">539</span><br><span class="line">540</span><br><span class="line">541</span><br><span class="line">542</span><br><span class="line">543</span><br><span class="line">544</span><br><span class="line">545</span><br><span class="line">546</span><br><span class="line">547</span><br><span class="line">548</span><br><span class="line">549</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.longrise.SWMS.Util;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.File;</span><br><span class="line"><span class="keyword">import</span> java.io.FileInputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.FileOutputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.OutputStream;</span><br><span class="line"><span class="keyword">import</span> java.text.SimpleDateFormat;</span><br><span class="line"><span class="keyword">import</span> java.util.Date;</span><br><span class="line"><span class="keyword">import</span> java.util.LinkedHashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.apache.poi.hssf.usermodel.HSSFDataFormat;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.hssf.util.HSSFColor;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.ss.usermodel.Cell;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.ss.usermodel.CellStyle;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.ss.usermodel.Font;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.ss.usermodel.RichTextString;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.ss.usermodel.Row;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.ss.usermodel.Sheet;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.ss.usermodel.Workbook;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.ss.util.CellRangeAddress;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.xssf.usermodel.XSSFCell;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.xssf.usermodel.XSSFCellStyle;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.xssf.usermodel.XSSFFont;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.xssf.usermodel.XSSFRichTextString;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.xssf.usermodel.XSSFWorkbook;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Excel 相关操作类(小数据量写入&lt;=60000)</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ExcelUtils</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">      <span class="comment">//设置单元格默认表宽</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> DEFAULT_COLUMN_SIZE = <span class="number">20</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 断言Excel文件写入之前的条件</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> directory 目录</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> fileName  文件名</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> file</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> IOException</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> File <span class="title">assertFile</span><span class="params">(String directory, String fileName)</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        File tmpFile = <span class="keyword">new</span> File(directory + File.separator + fileName + <span class="string">".xlsx"</span>);</span><br><span class="line">        <span class="keyword">if</span> (tmpFile.exists()) &#123;</span><br><span class="line">            <span class="keyword">if</span> (tmpFile.isDirectory()) &#123;</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> IOException(<span class="string">"File '"</span> + tmpFile + <span class="string">"' exists but is a directory"</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (!tmpFile.canWrite()) &#123;</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> IOException(<span class="string">"File '"</span> + tmpFile + <span class="string">"' cannot be written to"</span>);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            File parent = tmpFile.getParentFile();</span><br><span class="line">            <span class="keyword">if</span> (parent != <span class="keyword">null</span>) &#123;</span><br><span class="line">                <span class="keyword">if</span> (!parent.mkdirs() &amp;&amp; !parent.isDirectory()) &#123;</span><br><span class="line">                    <span class="keyword">throw</span> <span class="keyword">new</span> IOException(<span class="string">"Directory '"</span> + parent + <span class="string">"' could not be created"</span>);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> tmpFile;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 日期转化为字符串,格式为yyyy-MM-dd HH:mm:ss</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> String <span class="title">getCnDate</span><span class="params">(Date date)</span> </span>&#123;</span><br><span class="line">        String format = <span class="string">"yyyy-MM-dd HH:mm:ss"</span>;</span><br><span class="line">        SimpleDateFormat sdf = <span class="keyword">new</span> SimpleDateFormat(format);</span><br><span class="line">        <span class="keyword">return</span> sdf.format(date);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Excel 导出，POI实现</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> fileName    文件名</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> sheetName   sheet页名称</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> columnNames 表头列表名</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> sheetTitle  sheet页Title</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> titleInfo  打印信息</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> objects     目标数据集</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> File <span class="title">writeExcel</span><span class="params">(String directory, String fileName, String sheetName, List &lt; String &gt; columnNames,List&lt;String&gt; titleInfo,</span></span></span><br><span class="line"><span class="function"><span class="params">        String sheetTitle, List &lt; List &lt; Object &gt;&gt; objects, <span class="keyword">boolean</span> append)</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        File tmpFile = assertFile(directory, fileName);</span><br><span class="line">        <span class="keyword">return</span> exportExcel(tmpFile, sheetName, columnNames,titleInfo, sheetTitle, objects, append);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Excel 导出，POI实现，先写入Excel标题，与writeExcelData配合使用</span></span><br><span class="line"><span class="comment">     * 先使用writeExcelTitle再使用writeExcelData</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> directory   目录</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> fileName    文件名</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> sheetName   sheetName</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> columnNames 列名集合</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> sheetTitle  表格标题</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> append      是否在现有的文件追加</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> file</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> ReportInternalException</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> IOException</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> File <span class="title">writeExcelTitle</span><span class="params">(String directory, String fileName, String sheetName, List &lt; String &gt; columnNames,</span></span></span><br><span class="line"><span class="function"><span class="params">        String sheetTitle, <span class="keyword">boolean</span> append)</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        File tmpFile = assertFile(directory, fileName);</span><br><span class="line">        <span class="keyword">return</span> exportExcelTitle(tmpFile, sheetName, columnNames, sheetTitle, append);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Excel 导出，POI实现，写入Excel数据行列，与writeExcelTitle配合使用</span></span><br><span class="line"><span class="comment">     * 先使用writeExcelTitle再使用writeExcelData</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> directory 目录</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> fileName  文件名</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> sheetName sheetName</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> objects   数据信息</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> file</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> ReportInternalException</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> IOException</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> File <span class="title">writeExcelData</span><span class="params">(String directory, String fileName, String sheetName, List &lt; List &lt; Object &gt;&gt;</span></span></span><br><span class="line"><span class="function"><span class="params">        objects)</span></span></span><br><span class="line"><span class="function">    <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        File tmpFile = assertFile(directory, fileName);</span><br><span class="line">        <span class="keyword">return</span> exportExcelData(tmpFile, sheetName, objects);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 导出字符串数据</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> file        文件名</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> columnNames 表头</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> sheetTitle  sheet页Title</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> append      是否追加写文件</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> file</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> ReportInternalException</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> File <span class="title">exportExcelTitle</span><span class="params">(File file, String sheetName, List &lt; String &gt; columnNames,</span></span></span><br><span class="line"><span class="function"><span class="params">        String sheetTitle, <span class="keyword">boolean</span> append)</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        <span class="comment">// 声明一个工作薄</span></span><br><span class="line">        Workbook workBook;</span><br><span class="line">        <span class="keyword">if</span> (file.exists() &amp;&amp; append) &#123;</span><br><span class="line">            workBook = <span class="keyword">new</span> XSSFWorkbook(<span class="keyword">new</span> FileInputStream(file));</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            workBook = <span class="keyword">new</span> XSSFWorkbook();</span><br><span class="line">        &#125;</span><br><span class="line">        Map &lt; String, CellStyle &gt; cellStyleMap = styleMap(workBook);</span><br><span class="line">        <span class="comment">// 表头样式</span></span><br><span class="line">        CellStyle headStyle = cellStyleMap.get(<span class="string">"head"</span>);</span><br><span class="line">        <span class="comment">// 生成一个表格</span></span><br><span class="line">        Sheet sheet = workBook.getSheet(sheetName);</span><br><span class="line">        <span class="keyword">if</span> (sheet == <span class="keyword">null</span>) &#123;</span><br><span class="line">            sheet = workBook.createSheet(sheetName);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//最新Excel列索引,从0开始</span></span><br><span class="line">        <span class="keyword">int</span> lastRowIndex = sheet.getLastRowNum();</span><br><span class="line">        <span class="keyword">if</span> (lastRowIndex &gt; <span class="number">0</span>) &#123;</span><br><span class="line">            lastRowIndex++;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 设置表格默认列宽度</span></span><br><span class="line">        <span class="comment">//sheet.setDefaultColumnWidth(DEFAULT_COLUMN_SIZE);</span></span><br><span class="line">        <span class="comment">// 合并单元格</span></span><br><span class="line">        sheet.addMergedRegion(<span class="keyword">new</span> CellRangeAddress(lastRowIndex, lastRowIndex, <span class="number">0</span>, columnNames.size() - <span class="number">1</span>));</span><br><span class="line">        <span class="comment">// 产生表格标题行</span></span><br><span class="line">        Row rowMerged = sheet.createRow(lastRowIndex);</span><br><span class="line">        lastRowIndex++;</span><br><span class="line">        Cell mergedCell = rowMerged.createCell(<span class="number">0</span>);</span><br><span class="line">        mergedCell.setCellStyle(headStyle);</span><br><span class="line">        mergedCell.setCellValue(<span class="keyword">new</span> XSSFRichTextString(sheetTitle));</span><br><span class="line">        <span class="comment">// 产生表格表头列标题行</span></span><br><span class="line">        Row row = sheet.createRow(lastRowIndex);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; columnNames.size(); i++) &#123;</span><br><span class="line">            </span><br><span class="line">            Cell cell = row.createCell(i);</span><br><span class="line">            cell.setCellStyle(headStyle);</span><br><span class="line">            RichTextString text = <span class="keyword">new</span> XSSFRichTextString(columnNames.get(i));</span><br><span class="line">            cell.setCellValue(text);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            OutputStream ops = <span class="keyword">new</span> FileOutputStream(file);</span><br><span class="line">            workBook.write(ops);</span><br><span class="line">            ops.flush();</span><br><span class="line">            ops.close();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            System.err.println(e);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> file;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 导出字符串数据</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> file    文件名</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> objects 目标数据</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> ReportInternalException</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> File <span class="title">exportExcelData</span><span class="params">(File file, String sheetName, List &lt; List &lt; Object &gt;&gt; objects)</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        <span class="comment">// 声明一个工作薄</span></span><br><span class="line">        Workbook workBook;</span><br><span class="line">        <span class="keyword">if</span> (file.exists()) &#123;</span><br><span class="line">            workBook = <span class="keyword">new</span> XSSFWorkbook(<span class="keyword">new</span> FileInputStream(file));</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            workBook = <span class="keyword">new</span> XSSFWorkbook();</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        Map &lt; String, CellStyle &gt; cellStyleMap = styleMap(workBook);</span><br><span class="line">        <span class="comment">// 正文样式</span></span><br><span class="line">        CellStyle contentStyle = cellStyleMap.get(<span class="string">"content"</span>);</span><br><span class="line">        <span class="comment">//正文整数样式</span></span><br><span class="line">        CellStyle contentIntegerStyle = cellStyleMap.get(<span class="string">"integer"</span>);</span><br><span class="line">        <span class="comment">//正文带小数整数样式</span></span><br><span class="line">        CellStyle contentDoubleStyle = cellStyleMap.get(<span class="string">"double"</span>);</span><br><span class="line">        <span class="comment">// 生成一个表格</span></span><br><span class="line">        Sheet sheet = workBook.getSheet(sheetName);</span><br><span class="line">        <span class="keyword">if</span> (sheet == <span class="keyword">null</span>) &#123;</span><br><span class="line">            sheet = workBook.createSheet(sheetName);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//最新Excel列索引,从0开始</span></span><br><span class="line">        <span class="keyword">int</span> lastRowIndex = sheet.getLastRowNum();</span><br><span class="line">        <span class="keyword">if</span> (lastRowIndex &gt; <span class="number">0</span>) &#123;</span><br><span class="line">            lastRowIndex++;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 设置表格默认列宽度</span></span><br><span class="line">        <span class="comment">//sheet.setDefaultColumnWidth(DEFAULT_COLUMN_SIZE);</span></span><br><span class="line">        </span><br><span class="line">        <span class="comment">// 遍历集合数据,产生数据行,前两行为标题行与表头行</span></span><br><span class="line">        <span class="keyword">for</span> (List &lt; Object &gt; dataRow: objects) &#123;</span><br><span class="line">            Row row = sheet.createRow(lastRowIndex);</span><br><span class="line">            lastRowIndex++;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; dataRow.size(); j++) &#123;</span><br><span class="line">                Cell contentCell = row.createCell(j);</span><br><span class="line">                Object dataObject = dataRow.get(j);</span><br><span class="line">                </span><br><span class="line">                <span class="keyword">if</span> (dataObject != <span class="keyword">null</span>) &#123;</span><br><span class="line">                    sheet.autoSizeColumn(j, <span class="keyword">true</span>);</span><br><span class="line">                    sheet.setColumnWidth(j,dataObject.toString().length()*<span class="number">2</span>*<span class="number">256</span>);</span><br><span class="line">                    <span class="keyword">if</span> (dataObject <span class="keyword">instanceof</span> Integer) &#123;</span><br><span class="line">                        contentCell.setCellStyle(contentIntegerStyle);</span><br><span class="line">                        contentCell.setCellValue(Integer.parseInt(dataObject.toString()));</span><br><span class="line">                    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (dataObject <span class="keyword">instanceof</span> Double) &#123;</span><br><span class="line">                        contentCell.setCellStyle(contentDoubleStyle);</span><br><span class="line">                        contentCell.setCellValue(Double.parseDouble(dataObject.toString()));</span><br><span class="line">                    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (dataObject <span class="keyword">instanceof</span> Long &amp;&amp; dataObject.toString().length() == <span class="number">13</span>) &#123;</span><br><span class="line">                        contentCell.setCellStyle(contentStyle);</span><br><span class="line">                        contentCell.setCellValue(getCnDate(<span class="keyword">new</span> Date(Long.parseLong(dataObject.toString()))));</span><br><span class="line">                    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (dataObject <span class="keyword">instanceof</span> Date) &#123;</span><br><span class="line">                        contentCell.setCellStyle(contentStyle);</span><br><span class="line">                        contentCell.setCellValue(getCnDate((Date) dataObject));</span><br><span class="line">                    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                        contentCell.setCellStyle(contentStyle);</span><br><span class="line">                        contentCell.setCellValue(dataObject.toString());</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    contentCell.setCellStyle(contentStyle);</span><br><span class="line">                    <span class="comment">// 设置单元格内容为字符型</span></span><br><span class="line">                    contentCell.setCellValue(<span class="string">""</span>);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            OutputStream ops = <span class="keyword">new</span> FileOutputStream(file);</span><br><span class="line">            workBook.write(ops);</span><br><span class="line">            ops.flush();</span><br><span class="line">            ops.close();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            System.err.println(e);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> file;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 导出字符串数据</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> file        文件名</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> columnNames 表头</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> sheetTitle  sheet页Title</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> objects     目标数据</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> append      是否追加写文件</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> ReportInternalException</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> File <span class="title">exportExcel</span><span class="params">(File file, String sheetName, List &lt; String &gt; columnNames,List &lt;String &gt; titleInfo,</span></span></span><br><span class="line"><span class="function"><span class="params">        String sheetTitle, List &lt; List &lt; Object &gt;&gt; objects, <span class="keyword">boolean</span> append)</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        <span class="comment">// 声明一个工作薄</span></span><br><span class="line">        Workbook workBook;</span><br><span class="line">        <span class="keyword">if</span> (file.exists() &amp;&amp; append) &#123;</span><br><span class="line">            <span class="comment">// 声明一个工作薄</span></span><br><span class="line">            workBook = <span class="keyword">new</span> XSSFWorkbook(<span class="keyword">new</span> FileInputStream(file));</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            workBook = <span class="keyword">new</span> XSSFWorkbook();</span><br><span class="line">        &#125;</span><br><span class="line">        Map &lt; String, CellStyle &gt; cellStyleMap = styleMap(workBook);</span><br><span class="line">        <span class="comment">// 表头样式</span></span><br><span class="line">        CellStyle headStyle = cellStyleMap.get(<span class="string">"head"</span>);</span><br><span class="line">        <span class="comment">// 正文样式</span></span><br><span class="line">        CellStyle contentStyle = cellStyleMap.get(<span class="string">"content"</span>);</span><br><span class="line">        <span class="comment">//标题样式</span></span><br><span class="line">        CellStyle titleStyle = cellStyleMap.get(<span class="string">"title"</span>);</span><br><span class="line">       <span class="comment">//正文整数样式</span></span><br><span class="line">        CellStyle contentIntegerStyle = cellStyleMap.get(<span class="string">"integer"</span>);</span><br><span class="line">        <span class="comment">//正文带小数整数样式</span></span><br><span class="line">        CellStyle contentDoubleStyle = cellStyleMap.get(<span class="string">"double"</span>);</span><br><span class="line">        <span class="comment">// 生成一个表格</span></span><br><span class="line">        Sheet sheet = workBook.getSheet(sheetName);</span><br><span class="line">        <span class="keyword">if</span> (sheet == <span class="keyword">null</span>) &#123;</span><br><span class="line">            sheet = workBook.createSheet(sheetName);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//最新Excel列索引,从0开始</span></span><br><span class="line">        <span class="keyword">int</span> lastRowIndex = sheet.getLastRowNum();</span><br><span class="line">        <span class="keyword">if</span> (lastRowIndex &gt; <span class="number">0</span>) &#123;</span><br><span class="line">            lastRowIndex++;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 设置表格默认列宽度</span></span><br><span class="line">        sheet.setDefaultColumnWidth(DEFAULT_COLUMN_SIZE);</span><br><span class="line">        <span class="comment">// 合并单元格</span></span><br><span class="line">        sheet.addMergedRegion(<span class="keyword">new</span> CellRangeAddress(lastRowIndex, lastRowIndex, <span class="number">0</span>, columnNames.size() - <span class="number">1</span>));</span><br><span class="line">        <span class="comment">// 产生表格标题行</span></span><br><span class="line">        Row rowMerged = sheet.createRow(lastRowIndex);</span><br><span class="line">        lastRowIndex++;</span><br><span class="line">        Cell mergedCell = rowMerged.createCell(<span class="number">0</span>);</span><br><span class="line">        mergedCell.setCellStyle(headStyle);</span><br><span class="line">        mergedCell.setCellValue(<span class="keyword">new</span> XSSFRichTextString(sheetTitle));</span><br><span class="line">        <span class="comment">//产生打印信息行，并合并两个单元格</span></span><br><span class="line">        sheet.addMergedRegion(<span class="keyword">new</span> CellRangeAddress(lastRowIndex, lastRowIndex, <span class="number">1</span>,<span class="number">2</span>));</span><br><span class="line">        sheet.addMergedRegion(<span class="keyword">new</span> CellRangeAddress(lastRowIndex, lastRowIndex, <span class="number">4</span>,<span class="number">5</span>));</span><br><span class="line">        sheet.addMergedRegion(<span class="keyword">new</span> CellRangeAddress(lastRowIndex, lastRowIndex, <span class="number">6</span>,columnNames.size() - <span class="number">1</span>));</span><br><span class="line">        Row rowInfo = sheet.createRow(lastRowIndex);</span><br><span class="line">        lastRowIndex++;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; titleInfo.size(); i++) &#123;</span><br><span class="line">            Cell cell = rowInfo.createCell(i);</span><br><span class="line">            cell.setCellStyle(contentStyle);</span><br><span class="line">            RichTextString text = <span class="keyword">new</span> XSSFRichTextString(titleInfo.get(i));</span><br><span class="line">            cell.setCellValue(text);</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        <span class="comment">// 产生表格表头列标题行</span></span><br><span class="line">        Row row = sheet.createRow(lastRowIndex);</span><br><span class="line">        lastRowIndex++;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; columnNames.size(); i++) &#123;</span><br><span class="line">            Cell cell = row.createCell(i);</span><br><span class="line">            cell.setCellStyle(titleStyle);</span><br><span class="line">            RichTextString text = <span class="keyword">new</span> XSSFRichTextString(columnNames.get(i));</span><br><span class="line">            cell.setCellValue(text);</span><br><span class="line">        &#125;</span><br><span class="line">       </span><br><span class="line">        <span class="comment">// 遍历集合数据,产生数据行,前两行为标题行与表头行</span></span><br><span class="line">        <span class="keyword">for</span> (List &lt; Object &gt; dataRow: objects) &#123;</span><br><span class="line">            row = sheet.createRow(lastRowIndex);</span><br><span class="line">            lastRowIndex++;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; dataRow.size(); j++) &#123;</span><br><span class="line">                Cell contentCell = row.createCell(j);</span><br><span class="line">                Object dataObject = dataRow.get(j);</span><br><span class="line">                <span class="keyword">if</span> (dataObject != <span class="keyword">null</span>) &#123;</span><br><span class="line">                    <span class="comment">//sheet.autoSizeColumn(j, true);</span></span><br><span class="line">                    <span class="comment">//sheet.setColumnWidth(j,maxLongth*3*256);</span></span><br><span class="line">                    <span class="keyword">if</span> (dataObject <span class="keyword">instanceof</span> Integer) &#123;</span><br><span class="line">                        contentCell.setCellType(XSSFCell.CELL_TYPE_NUMERIC);</span><br><span class="line">                        contentCell.setCellStyle(contentIntegerStyle);</span><br><span class="line">                        contentCell.setCellValue(Integer.parseInt(dataObject.toString()));</span><br><span class="line">                    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (dataObject <span class="keyword">instanceof</span> Double) &#123;</span><br><span class="line">                        contentCell.setCellType(XSSFCell.CELL_TYPE_NUMERIC);</span><br><span class="line">                        contentCell.setCellStyle(contentDoubleStyle);</span><br><span class="line">                        contentCell.setCellValue(Double.parseDouble(dataObject.toString()));</span><br><span class="line">                    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (dataObject <span class="keyword">instanceof</span> Long &amp;&amp; dataObject.toString().length() == <span class="number">13</span>) &#123;</span><br><span class="line">                        contentCell.setCellType(XSSFCell.CELL_TYPE_STRING);</span><br><span class="line">                        contentCell.setCellStyle(contentStyle);</span><br><span class="line">                        contentCell.setCellValue(getCnDate(<span class="keyword">new</span> Date(Long.parseLong(dataObject.toString()))));</span><br><span class="line">                    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (dataObject <span class="keyword">instanceof</span> Date) &#123;</span><br><span class="line">                        contentCell.setCellType(XSSFCell.CELL_TYPE_STRING);</span><br><span class="line">                        contentCell.setCellStyle(contentStyle);</span><br><span class="line">                        contentCell.setCellValue(getCnDate((Date) dataObject));</span><br><span class="line">                    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                        contentCell.setCellType(XSSFCell.CELL_TYPE_STRING);</span><br><span class="line">                        contentCell.setCellStyle(contentStyle);</span><br><span class="line">                        contentCell.setCellValue(dataObject.toString());</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    contentCell.setCellStyle(contentStyle);</span><br><span class="line">                    <span class="comment">// 设置单元格内容为字符型</span></span><br><span class="line">                    contentCell.setCellValue(<span class="string">""</span>);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            OutputStream ops = <span class="keyword">new</span> FileOutputStream(file);</span><br><span class="line">            workBook.write(ops);</span><br><span class="line">            ops.flush();</span><br><span class="line">            ops.close();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            System.err.println(e);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> file;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 创建单元格表头样式</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> workbook 工作薄</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> CellStyle <span class="title">createCellHeadStyle</span><span class="params">(Workbook workbook)</span> </span>&#123;</span><br><span class="line">        CellStyle style = workbook.createCellStyle();</span><br><span class="line">        <span class="comment">// 设置边框样式</span></span><br><span class="line">        style.setBorderBottom(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderLeft(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderRight(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderTop(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        <span class="comment">//设置对齐样式</span></span><br><span class="line">        style.setAlignment(XSSFCellStyle.ALIGN_CENTER);</span><br><span class="line">        <span class="comment">// 生成字体</span></span><br><span class="line">        Font font = workbook.createFont();</span><br><span class="line">        <span class="comment">// 表头样式</span></span><br><span class="line">        style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);</span><br><span class="line">        font.setFontHeightInPoints((<span class="keyword">short</span>) <span class="number">16</span>);</span><br><span class="line">        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);</span><br><span class="line">        <span class="comment">// 把字体应用到当前的样式</span></span><br><span class="line">        style.setFont(font);</span><br><span class="line">        <span class="keyword">return</span> style;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 创建单元格标题样式</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> workbook</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> CellStyle <span class="title">createCellTitleStyle</span><span class="params">(Workbook workbook)</span> </span>&#123;</span><br><span class="line">        CellStyle style = workbook.createCellStyle();</span><br><span class="line">        <span class="comment">// 设置边框样式</span></span><br><span class="line">        style.setBorderBottom(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderLeft(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderRight(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderTop(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        <span class="comment">//设置对齐样式</span></span><br><span class="line">        style.setAlignment(XSSFCellStyle.ALIGN_CENTER);</span><br><span class="line">        <span class="comment">// 生成字体</span></span><br><span class="line">        Font font = workbook.createFont();</span><br><span class="line">        <span class="comment">// 表头样式</span></span><br><span class="line">        style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);</span><br><span class="line">        style.setFillForegroundColor(HSSFColor.SKY_BLUE.index);</span><br><span class="line">        font.setFontHeightInPoints((<span class="keyword">short</span>) <span class="number">12</span>);</span><br><span class="line">        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);</span><br><span class="line">        <span class="comment">// 把字体应用到当前的样式</span></span><br><span class="line">        style.setFont(font);</span><br><span class="line">        <span class="keyword">return</span> style;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 创建单元格正文样式</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> workbook 工作薄</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> CellStyle <span class="title">createCellContentStyle</span><span class="params">(Workbook workbook)</span> </span>&#123;</span><br><span class="line">        CellStyle style = workbook.createCellStyle();</span><br><span class="line">        <span class="comment">// 设置边框样式</span></span><br><span class="line">        style.setBorderBottom(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderLeft(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderRight(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderTop(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        <span class="comment">//设置对齐样式</span></span><br><span class="line">        style.setAlignment(XSSFCellStyle.ALIGN_CENTER);</span><br><span class="line">        <span class="comment">//自动换行</span></span><br><span class="line">        style.setWrapText(<span class="keyword">true</span>);</span><br><span class="line">        <span class="comment">// 生成字体</span></span><br><span class="line">        Font font = workbook.createFont();</span><br><span class="line">        <span class="comment">// 正文样式</span></span><br><span class="line">        style.setFillPattern(XSSFCellStyle.NO_FILL);</span><br><span class="line">        style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);</span><br><span class="line">        font.setBoldweight(XSSFFont.BOLDWEIGHT_NORMAL);</span><br><span class="line">        <span class="comment">// 把字体应用到当前的样式</span></span><br><span class="line">        style.setFont(font);</span><br><span class="line">        <span class="keyword">return</span> style;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 单元格样式(Integer)列表</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> CellStyle <span class="title">createCellContent4IntegerStyle</span><span class="params">(Workbook workbook)</span> </span>&#123;</span><br><span class="line">        CellStyle style = workbook.createCellStyle();</span><br><span class="line">        <span class="comment">// 设置边框样式</span></span><br><span class="line">        style.setBorderBottom(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderLeft(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderRight(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderTop(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        <span class="comment">//设置对齐样式</span></span><br><span class="line">        style.setAlignment(XSSFCellStyle.ALIGN_CENTER);</span><br><span class="line">        <span class="comment">// 生成字体</span></span><br><span class="line">        Font font = workbook.createFont();</span><br><span class="line">        <span class="comment">// 正文样式</span></span><br><span class="line">        style.setFillPattern(XSSFCellStyle.NO_FILL);</span><br><span class="line">        style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);</span><br><span class="line">        font.setBoldweight(XSSFFont.BOLDWEIGHT_NORMAL);</span><br><span class="line">        <span class="comment">// 把字体应用到当前的样式</span></span><br><span class="line">        style.setFont(font);</span><br><span class="line">        style.setDataFormat(HSSFDataFormat.getBuiltinFormat(<span class="string">"#,##0"</span>)); <span class="comment">//数据格式只显示整数</span></span><br><span class="line">        <span class="keyword">return</span> style;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 单元格样式(Double)列表</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> CellStyle <span class="title">createCellContent4DoubleStyle</span><span class="params">(Workbook workbook)</span> </span>&#123;</span><br><span class="line">        CellStyle style = workbook.createCellStyle();</span><br><span class="line">        <span class="comment">// 设置边框样式</span></span><br><span class="line">        style.setBorderBottom(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderLeft(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderRight(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        style.setBorderTop(XSSFCellStyle.BORDER_THIN);</span><br><span class="line">        <span class="comment">//设置对齐样式</span></span><br><span class="line">        style.setAlignment(XSSFCellStyle.ALIGN_CENTER);</span><br><span class="line">        <span class="comment">// 生成字体</span></span><br><span class="line">        Font font = workbook.createFont();</span><br><span class="line">        <span class="comment">// 正文样式</span></span><br><span class="line">        style.setFillPattern(XSSFCellStyle.NO_FILL);</span><br><span class="line">        style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);</span><br><span class="line">        font.setBoldweight(XSSFFont.BOLDWEIGHT_NORMAL);</span><br><span class="line">        <span class="comment">// 把字体应用到当前的样式</span></span><br><span class="line">        style.setFont(font);</span><br><span class="line">        style.setDataFormat(HSSFDataFormat.getBuiltinFormat(<span class="string">"#,##0.00"</span>)); <span class="comment">//保留两位小数点</span></span><br><span class="line">        <span class="keyword">return</span> style;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 单元格样式列表</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> Map &lt; String, CellStyle &gt; styleMap(Workbook workbook) &#123;</span><br><span class="line">        Map &lt; String, CellStyle &gt; styleMap = <span class="keyword">new</span> LinkedHashMap &lt;String, CellStyle &gt; ();</span><br><span class="line">        styleMap.put(<span class="string">"head"</span>, createCellHeadStyle(workbook));</span><br><span class="line">        styleMap.put(<span class="string">"title"</span>, createCellTitleStyle(workbook));</span><br><span class="line">        styleMap.put(<span class="string">"content"</span>, createCellContentStyle(workbook));</span><br><span class="line">        styleMap.put(<span class="string">"integer"</span>, createCellContent4IntegerStyle(workbook));</span><br><span class="line">        styleMap.put(<span class="string">"double"</span>, createCellContent4DoubleStyle(workbook));</span><br><span class="line">        <span class="keyword">return</span> styleMap;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="测试类"><a href="#测试类" class="headerlink" title="测试类"></a>测试类</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> client;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.sql.Date;</span><br><span class="line"><span class="keyword">import</span> java.util.LinkedList;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"><span class="keyword">import</span> tools.ExcelUtils;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ExploreTest</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        String sheetName = <span class="string">"sheet名字"</span>;</span><br><span class="line">        String sheetTitle = <span class="string">"标头"</span>;</span><br><span class="line">        List &lt; String &gt; columnNames = <span class="keyword">new</span> LinkedList &lt; &gt; ();</span><br><span class="line">        columnNames.add(<span class="string">"测试标头长度自适应测试标头长度自适应测试标头长度自适应"</span>);</span><br><span class="line">        columnNames.add(<span class="string">"单元格2"</span>);</span><br><span class="line">        columnNames.add(<span class="string">"单元格3"</span>);</span><br><span class="line">        columnNames.add(<span class="string">"单元格4"</span>);</span><br><span class="line">        columnNames.add(<span class="string">"单元格5"</span>);</span><br><span class="line">        columnNames.add(<span class="string">"单元格6"</span>);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="comment">//写入标题--第二种方式</span></span><br><span class="line">        ExcelUtils.writeExcelTitle(<span class="string">"D:\\tset"</span>, <span class="string">"biaoming1"</span>, sheetName, columnNames, sheetTitle, <span class="keyword">false</span>);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        List &lt; List &lt; Object &gt;&gt; objects = <span class="keyword">new</span> LinkedList &lt; &gt; ();</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++) &#123;</span><br><span class="line">            List &lt; Object &gt; dataA = <span class="keyword">new</span> LinkedList &lt; &gt; ();</span><br><span class="line">            dataA.add(<span class="string">"哈哈"</span>);</span><br><span class="line">            dataA.add(<span class="keyword">new</span> Date(<span class="number">1451036631012L</span>));</span><br><span class="line">            dataA.add(<span class="number">1451036631012L</span>);</span><br><span class="line">            dataA.add(<span class="string">"测试标头长度自适应测试标头长度自适应测试标头长度自适应"</span>);</span><br><span class="line">            dataA.add(i);</span><br><span class="line">            dataA.add(<span class="number">1.323</span> + i);</span><br><span class="line">            objects.add(dataA);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="comment">//写入数据--第二种方式</span></span><br><span class="line">        	ExcelUtils.writeExcelData(<span class="string">"D:\\tset"</span>, <span class="string">"biaoming1"</span>, sheetName, objects);</span><br><span class="line">            <span class="comment">//直接写入数据--第一种方式</span></span><br><span class="line">        	ExcelUtils.writeExcel(<span class="string">"D:\\tset"</span>, <span class="string">"biaoming2"</span>, sheetName, columnNames, sheetTitle, objects, <span class="keyword">false</span>);</span><br><span class="line">        	System.out.println(<span class="string">"数据写入成功！"</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
      <!-- reward -->
      
      <div id="reward-btn">
        Donate
      </div>
      
    </div>
    
    
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>Copyright： </strong>
              Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://bodboy.gitee.io/blog/2020/04/18/%E5%AF%BC%E5%87%BAExcel%E6%96%87%E6%A1%A3%EF%BC%88%E5%AE%9A%E5%AE%BD%E8%87%AA%E5%8A%A8%E6%8D%A2%E8%A1%8C%EF%BC%89/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/excel/" rel="tag">excel</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/java/" rel="tag">java</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/blog/2020/04/18/%E6%8B%A6%E6%88%AA%E5%99%A8/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            spring之拦截器
          
        </div>
      </a>
    
    
      <a href="/blog/2020/04/18/%E5%AF%86%E7%A0%81%E5%8A%A0%E5%AF%86/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">java工具类（MD5加密）</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        app_id: 'uW8QYGvvhWmNWdiwpznJ0GVa-gzGzoHsz',
        app_key: 'LrJhMzx9qEwcMV1DJjTI6f6C',
        path: window.location.pathname,
        notify: 'false',
        verify: 'false',
        avatar: '[object Object]',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2019-2021
        <i class="ri-heart-fill heart_icon"></i> panda
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        Powered by <a href="https://hexo.io" target="_blank">Hexo</a>
        <span class="division">|</span>
        Theme - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/blog/"><img src="https://portrait.gitee.com/uploads/avatars/user/1007/3023420_bodboy_1578973210.png!avatar200" alt="小熊的博客"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/tags/%E6%97%85%E8%A1%8C/">旅行</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/blog/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/blog/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/blog/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/blog/js/jquery-2.0.3.min.js"></script>


<script src="/blog/js/lazyload.min.js"></script>


<script>
  try {
    var typed = new Typed("#subtitle", {
      strings: ['面朝大海，春暖花开', '愿你一生努力，一生被爱', '想要的都拥有，得不到的都释怀'],
      startDelay: 0,
      typeSpeed: 200,
      loop: true,
      backSpeed: 100,
      showCursor: true
    });
  } catch (err) {
  }

</script>




<script src="/blog/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>



<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/blog/dist/main.js"></script>



<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>


<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>




<script src="/blog/js/busuanzi-2.3.pure.min.js"></script>



<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>

  
<script src="/blog/js/clickLove.js"></script>



<!-- 复制 -->



    
    <div id="music">
    
    
    
    <iframe frameborder="no" border="1" marginwidth="0" marginheight="0" width="200" height="52"
        src="//music.163.com/outchain/player?type=2&id=1297802566&auto=1&height=32"></iframe>
</div>

<style>
    #music {
        position: fixed;
        right: 15px;
        bottom: 0;
        z-index: 998;
    }
</style>
    
  </div>
</body>

</html>